package cn.e4j.modular.api.service;


import cn.e4j.core.dto.impl.Dto;
import cn.e4j.core.util.DateUtils;
import cn.e4j.core.util.InvokeUtil;
import cn.e4j.core.util.LangUtils;
import cn.e4j.core.util.ToolUtil;
import cn.e4j.modular.api.mapper.WttdMapper;
import cn.e4j.modular.api.util.CommonUtils;
import cn.e4j.modular.crm.entity.EsaaT;
import cn.e4j.modular.system.entity.SysUser;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.math.BigDecimal;
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@Service
public class WttdService {

    @Autowired
    WttdMapper wttdMapper;

    @Transactional(readOnly = true)
    public List<Dto> getEsaaData(Dto indto){
        List <Dto> list = wttdMapper.getEsaaData(indto);
        return  list;
    }

    @Transactional(readOnly = true)
    public List<Dto> getCpxData(Dto indto){
        List <Dto> list = wttdMapper.getCpxData(indto);
        return  list;
    }

    /**
     * 问题提单提交
     * @param inDto
     */
    @Transactional
    public void addData(SysUser userModel, Dto inDto){
        LocalDate now = LocalDate.now();
        JSONArray orderList = JSONArray.parseArray(inDto.getString("orderList"));
        String ESAADOCNO = DateUtils.formatDate(new Date(), "yyyyMMddHHmmssSSS");
        EsaaT esaaT = new EsaaT();
        esaaT.setESAADOCNO(ESAADOCNO);
        esaaT.setESAA001(inDto.getString("ESAA001"));
        esaaT.setESAA003(inDto.getString("ESAA003"));
        esaaT.setESAA005(inDto.getString("ESAA005"));
        esaaT.setESAA006(inDto.getString("ESAA006"));
        esaaT.setESAA007(inDto.getString("ESAA007"));
        esaaT.setESAA008(inDto.getString("ESAA008"));
        esaaT.setESAA002(userModel.getNAME());
        esaaT.setESAA004(LocalDate.now());
        esaaT.setESAA009(inDto.getString("ESAA009"));
        esaaT.setESAASTUS("1");
        esaaT.setESAA012(inDto.getString("ESAA012"));
        esaaT.setESAA014(inDto.getString("ESAA014"));
        esaaT.insert();
    }

}
